/* eslint valid-jsdoc: "off" */

'use strict';
const path = require("path");

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1639923271883_801';

  // add your middleware config here
  config.middleware = ['errorHandler', 'auth'];

  // CSRF enable false
  config.security = {
    csrf: {
      enable: false
    }
  }
  config.cluster = {
    listen: {
      path: '',
      // port: 9090,
      port: 8085,
      hostname: '0.0.0.0',
    }
  };

  config.view = {
    mapping: {
      ".html": "ejs"
    }
  }

  config.ejs = {
    // delimiter: "$"
  }

  config.static = {
    // 静态化访问前缀,如：`http://127.0.0.1:9090/static/1.png`
    prefix: '/static',
    dir: path.join(appInfo.baseDir, 'app/public'), // `String` or `Array:[dir1, dir2, ...]` 静态化目录,可以设置多个静态化目录
    dynamic: true, // 如果当前访问的静态资源没有缓存，则缓存静态文件，和`preload`配合使用；
    preload: false,
    maxAge: 31536000, // in prod env, 0 in other envs
    buffer: true, // in prod env, false in other envs
  };

  config.session = {
    key: 'SHAN_GUAGUA',
    httpOnly: true,
    maxAge: 1000 * 10,
    renew: true
  }

  // config.websocket = {
  //   enable: true,
  // }

  // config/config.default.js

  config.multipart = {
    fields: 50, // 表单上传字段限制的个数
    files: 10,
    // 只允许上传的图片格式
    whitelist: ['.png', '.jpg', '.jpeg', '.xlsx', '.pdf', '.xls', '.ppt', '.zip', '.txt', '.rar', '.docx', ".mp4",
      ".avi",
      ".wmv",
      ".mov",
      ".flv",
      ".rmvb",
      ".3gp",
      ".m4v",
      ".mkv",
      '.xls',
      '.wgt',
      '.pem'],
    // 文件允许大小
    fileSize: '50mb',
  }

  config.logger = {
    level: 'INFO',
    dir: 'logs',
    dir: path.join(__dirname, '../logs')
  };

  config.sequelize = {
    dialect: 'mysql',
    host: '106.52.21.126', // 腾讯云
    // host: '10.0.12.4', // 腾讯云
    port: 3307,
    // database: 'super',
    database: 'expresswayCamera',
    username: 'root',
    password: '513164001lzs',
    // 配置数据库时间为东八区北京时间
    timezone: '+08:00',
    define: {  // model的全局配置
      timestamps: false,   // 添加create,update,delete时间戳
      paranoid: true,   // 添加软删除
      freezeTableName: true,  // 防止修改表名为复数
      underscored: false  // 防止驼峰式字段被默认转为下划线
    },
    // 打印日志
    logging: false,
    // 时间格式化
    dialectOptions: {
      charset: 'utf8mb4',
      dateStrings: true,
      typeCast: true
    },
    pool: {
      max: 1000,
      min: 0,
      acquire: 100 * 1000,
      idle: 10000 // 链接空置时间（毫秒），超时后将释放链接
    },
    retry: { // 设置自动查询时的重试标志
      max: 8 // 设置重试次数
    }
  };

  config.jwt = {
    secret: 'shanguagua',
  };

  config.bodyParser = {
    enableTypes: ['json', 'form'],
    jsonLimit: '1mb',
    formLimit: '1mb'
  };

  const userConfig = {
    imgDomain: "https://cdn.shanzhonglei.com",
    mediasBaseUrl: "http://127.0.0.1:8085/static/medias"
  };

  return {
    ...config,
    userConfig,
  };
};

